package com.lvhengchang.pojo;

public class Result<T> {
	private String msg = "success";
	private int code = 200;
	private T data;

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public static Result<?> fail() {
		return fail(500, "fail");
	}

	public static Result<?> fail(String msg) {
		return fail(500, msg);
	}

	public static Result<?> fail(int code, String msg) {
		Result<?> result = new Result<Object>();
		result.setMsg(msg);
		result.setCode(code);
		return result;
	}

	public static Result<?> success() {
		return success(null, FinalVar.MSG);
	}

	public static Result<?> success(String msg) {
		return success(null, msg);
	}

	public static <T> Result<T> success(T data) {
		return success(data, null);
	}

	public static <T> Result<T> success(T data, String msg) {
		Result<T> result = new Result<>();
		result.setData(data);
		result.setMsg(msg);
		return result;
	}
}
